package zengjin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zengjin.common.PageResponse;
import zengjin.common.R;
import zengjin.model.dto.news.AddNewRequest;
import zengjin.model.dto.news.PageNewRequest;
import zengjin.model.dto.send.PageSendRequest;
import zengjin.model.vo.news.PageNewVO;
import zengjin.service.NewService;

/**
 * @author 19324
 */
@Tag(name = "消息相关接口")
@RestController
@RequestMapping("/new")
@Slf4j
public class NewController {


    @Resource
    private NewService newService;

    //1. 添加消息
    @Operation(summary = "添加消息")
    @PostMapping("/addNew")
    public R<Boolean> addNew(@RequestBody AddNewRequest addNewRequest) {
        //1. 参数校验
        if (addNewRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2. 调用service
        Boolean addNewResult = newService.addNew(addNewRequest);
        if (!addNewResult) {
            return R.error(false, "添加消息失败");
        }
        return R.success(true, "添加消息成功");
    }

    //2. 删除消息
    @Operation(summary = "删除消息")
    @PostMapping("/deleteNew")
    public R<Boolean> deleteNew(Long newId) {
        //1. 参数校验
        if (newId == null) {
            throw new RuntimeException("参数为空");
        }
        //2. 调用service
        Boolean deleteNewResult = newService.removeById(newId);
        if (!deleteNewResult) {
            return R.error(false, "删除消息失败");
        }
        return R.success(true, "删除消息成功");
    }
    //3. 获取消息
    //4. 分页获取消息
    @Operation(summary = "分页获取消息")
    @PostMapping("/pageNew")
    public R<PageResponse<PageNewVO>> pageNew(@RequestBody PageNewRequest pageNewRequest) {
        //1. 参数校验
        if (pageNewRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2. 调用service
        PageResponse<PageNewVO> pageNewResult = newService.pageNew(pageNewRequest);
        if (pageNewResult == null) {
            return R.error(null, "分页获取消息失败");
        }
        return R.success(pageNewResult, "分页获取消息成功");
    }



    //5. 获取消息数量
    //6. 获取消息列表






}
